package com.lzx.guanchajava.adapter.topicListAdapter

import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.lzx.guanchajava.pojo.bean.topicList.TopicItem
import com.lzx.guanchajava.R
import com.lzx.guanchajava.adapter.BaseRecyclerViewAdapter
import com.lzx.guanchajava.databinding.ItemTopicListBinding
import com.lzx.guanchajava.view.widget.UrlImageView
import com.orhanobut.logger.Logger
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick

class TopicListAdapter : BaseRecyclerViewAdapter<TopicItem>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
            TopicHolder(
                    DataBindingUtil.inflate(
                            LayoutInflater.from(parent.context),
                            R.layout.item_topic_list,
                            parent,
                            false)
            )

    override fun getItemCount(): Int = data.size


    class Holder(view: View) : RecyclerView.ViewHolder(view) {
        val user_pic = view.findViewById<UrlImageView>(R.id.topic_user_pic)
        val user_name = view.findViewById<TextView>(R.id.topic_user_name)
        val pic = view.findViewById<UrlImageView>(R.id.topic_pic)
        val title = view.findViewById<TextView>(R.id.topic_title)
        val tag = view.findViewById<TextView>(R.id.topic_tag)
        val comment_btn = view.findViewById<TextView>(R.id.topic_comment_btn)
        val time = view.findViewById<TextView>(R.id.topic_time)
    }


    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val topic = data[position]
        (holder as TopicHolder).binding.data = topic
    }
}